import Card, { type ICardView } from '.';
import type BaseControlService from '../../controls/base/service';
import DI from '../../utils/di';

class CardService extends DI implements ICardView {
  title: string;
  controls: BaseControlService[];

  visible = true;
  component = Card;
  constructor({ title, controls }: { title: string; controls: BaseControlService[] }) {
    super();
    this.title = title;
    this.controls = controls;
  }

  getLabelWidth() {
    return this.controls.reduce((pre, cur) => {
      return Math.max(pre, cur.getLabelWidth());
    }, 0);
  }

  init() {
    this.controls.forEach(it => {
      it.bindBpmnService(this.root);
      it.bindPanelService(this.panel);
      it.bindParent(this);
    });
    this.controls.forEach(it => {
      it.init();
    });
  }

  onShow() {
    this.controls.forEach(it => {
      it.onShow?.();
    });
  }
}

export default CardService;
